<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui">

<h:head></h:head>
<body>
	<h:form>
		<p:menubar>
			<p:menuitem
				value="SISTEMA DE VENTAS Y ALMACEN DE BIENES COMPUTACIONALES"
				style="font-size:12px;"></p:menuitem>
		</p:menubar>

		<p:panel header="Iniciar Sesión" style="width: 450px; margin:160px auto;">
			
			<h:panelGrid columns="2" cellpadding="10">
						<h:outputLabel for="username" value="Username:" />
                        <p:inputText id="username" value="#{loginBean.username}" required="true" label="username" />
                        <h:outputLabel for="password" value="Password:" />
                        <p:password id="password" value="#{loginBean.password}" required="true" label="password" />
				<p:outputLabel value="Perfil" />
				<h:form>
					<p:selectOneMenu immediate="true" value="#{loginBean.rol}">
						<f:selectItem itemLabel="Elija un perfil" itemValue=""></f:selectItem>
						<f:selectItem itemLabel="Logística" itemValue="logistica"></f:selectItem>
						<f:selectItem itemLabel="Almacen" itemValue="almacen"></f:selectItem>
						<f:selectItem itemLabel="Ventas" itemValue="ventas"></f:selectItem>
						<f:selectItem itemLabel="Administrador" itemValue="administrador"></f:selectItem>
					</p:selectOneMenu>
				</h:form>
			</h:panelGrid>
			
			<p:commandButton value="Entrar" style="margin:0 0 0 150px;" actionListener="#{loginBean.login}" 
                                             oncomplete="handleLoginRequest(args)"></p:commandButton>

		</p:panel>
	</h:form>
	
	<script type="text/javascript">
            function handleLoginRequest( args) {
                if (args.validationFailed || !args.loggedIn) {
                    jQuery('#formLogin').effect("shake", {times: 5}, 100);
                }
                else {
                    $('#formLogin').fadeOut();
                    location.href= "http://localhost:8080/primefaces-intro/"+args.ruta;
                }
            }
        </script>
	
</body>
</html>
